package com.github.sbb.sherry.console.controller.engine.config;

import com.github.sbb.sherry.common.base.Preconditions;
import com.github.sbb.sherry.console.dto.PageList;
import com.github.sbb.sherry.console.service.engine.config.FetcherConfigService;
import com.github.sbb.sherry.repository.entity.Fetcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
@RestController
@RequestMapping("engine/config/fetcher")
public class FetcherConfigController {

  @Autowired
  private FetcherConfigService fetcherConfigService;

  @PostMapping("add")
  public void addFetcher(@RequestBody Fetcher fetcher) {
    Preconditions.checkNotNull(fetcher);
    fetcherConfigService.addFetcher(fetcher);
  }

  @GetMapping("list")
  public PageList<Fetcher> list(int currentPage, Integer pageSize) {
    return fetcherConfigService.pageList(currentPage, pageSize);
  }
}
